/**
 * 
 */
package com.palmwindActivity.settings;


import com.palmwindActivity.R;
import com.palmwindActivity.app.AbstractActivity;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

/**
 * @author albertma
 *
 */
public class SettingActivity extends AbstractActivity implements Button.OnClickListener, TextWatcher{

	public static final String PREFS_NAME = "Settings";
	Button button = null;
	EditText editText = null;
	SharedPreferences settings;
	/**
	 * 
	 */
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		this.setTitle(R.string.title_input_ip);
		this.setContentView(R.layout.setting);
		button = (Button)findViewById(R.id.Button01);
		editText = (EditText)findViewById(R.id.IPEditText);
		
		
		settings = getSharedPreferences(PREFS_NAME, 0);
	
	
		

	}
	protected void onStartDelegate()
	{
		editText.addTextChangedListener(this);
		button.setOnClickListener(this);
		String ipStr = settings.getString("ip", "");
		boolean hasPreference = ipStr.trim().length() > 0 ? true : false;

		button.setEnabled(hasPreference);
		button.setClickable(hasPreference);
		editText.setText(ipStr);
	}
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(button.getId() == R.id.Button01 && editText.getText().length() > 0 )
		{
			 Editor editor = settings.edit();
			 editor.putString("ip", editText.getText().toString());
			 editor.commit();
			 finish();
		}
	}
	public void afterTextChanged(Editable s) {
		// TODO Auto-generated method stub
		
	}
	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {
		// TODO Auto-generated method stub
		
	}
	public void onTextChanged(CharSequence s, int start, int before, int count) {
		if(s.toString().trim().length() > 0)
		{
			button.setEnabled(true);
			button.setClickable(true);
		}
		else
		{
			button.setEnabled(false);
			button.setClickable(false);
		}
	}
	

}
